package com.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.config.InterfaceModule;
import com.dao.UpdatePwdDao;
import com.dto.UserInfo;
import com.service.UpdatePwdService;

@Service
public class UpdatePwdServiceImpl implements UpdatePwdService {
	
	@Autowired
	private UpdatePwdDao upd;
	
	//发送短信验证
	@Override
	public UserInfo getUserByPhone(String phone) {
		UserInfo user=upd.getUserByPhone(phone);
		if(user==null) {
			return null;
		}else {
			//得到电话号码
			String p=user.getPhone();
			//随机出验证码
			String code=(int)(Math.random()*9000)+1000+"";
			//调用短信接口类
			InterfaceModule im=new InterfaceModule();
			im.noteInterface(p, code);
			//将验证码和电话号码存入数据库
			Map<String,String> map=new HashMap<String,String>();
			map.put("phone", user.getPhone());
			map.put("code", code);
			upd.InsertCode(map);
			return user;
		}
	}

	//判断输入的验证码是否正确
	@Override
	public String getPhoneByCodeAndPhone(Map<String,String> map) {
		String s=upd.getPhoneByCodeAndPhone(map);
		return s;
	}
	
	//根据电话号码修改密码
	@Override
	public void updatePassword(Map<String, String> map) {
		upd.updatePassword(map);
	}

}
